import 'package:finance_app/src/entities/payslips_item_entity.dart';
import 'package:finance_app/src/entities/employee_contact_entity.dart';
import 'package:finance_app/src/entities/transaction_entity.dart';

payslipsItemEntityFromJson(PayslipsItemEntity data, Map<String, dynamic> json) {
	if (json['data_type'] != null) {
		data.dataType = json['data_type'].toString();
	}
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['company_id'] != null) {
		data.companyId = json['company_id'] is String
				? int.tryParse(json['company_id'])
				: json['company_id'].toInt();
	}
	if (json['employee_id'] != null) {
		data.employeeId = json['employee_id'] is String
				? int.tryParse(json['employee_id'])
				: json['employee_id'].toInt();
	}
	if (json['payment_type_id'] != null) {
		data.paymentTypeId = json['payment_type_id'];
	}
	if (json['payment_type_name'] != null) {
		data.paymentTypeName = json['payment_type_name'].toString();
	}
	if (json['paid_at'] != null) {
		data.paidAt = json['paid_at'].toString();
	}
	if (json['number'] != null) {
		data.number = json['number'].toString();
	}
	if (json['start_date'] != null) {
		data.startDate = json['start_date'].toString();
	}
	if (json['end_date'] != null) {
		data.endDate = json['end_date'].toString();
	}
	if (json['total_days'] != null) {
		data.totalDays = json['total_days'] is String
				? num.tryParse(json['total_days'])
				: json['total_days'];
	}
	if (json['actual_days'] != null) {
		data.actualDays = json['actual_days'] is String
				? num.tryParse(json['actual_days'])
				: json['actual_days'];
	}
	if (json['contribution'] != null) {
		data.contribution = json['contribution'].toString();
	}
	if (json['contribution_amount'] != null) {
		data.contributionAmount = json['contribution_amount'].toString();
	}
	if (json['income_data'] != null) {
		data.incomeData = (json['income_data'] as List).map((v) => EmployeeContactIncomeData().fromJson(v)).toList();
	}
	if (json['deduction_data'] != null) {
		data.deductionData = (json['deduction_data'] as List).map((v) => EmployeeContactDeductionData().fromJson(v)).toList();
	}
	if (json['payments'] != null) {
		data.payments = (json['payments'] as List).map((v) => TransactionEntity().fromJson(v)).toList();
	}
	if (json['total'] != null) {
		data.total = json['total'] is String
				? num.tryParse(json['total'])
				: json['total'];
	}
	if (json['employee_cpf'] != null) {
		data.employeeCpf = json['employee_cpf'] is String
				? double.tryParse(json['employee_cpf'])
				: json['employee_cpf'].toDouble();
	}
	if (json['employer_cpf'] != null) {
		data.employerCpf = json['employer_cpf'] is String
				? int.tryParse(json['employer_cpf'])
				: json['employer_cpf'].toInt();
	}
	if (json['nett_amount'] != null) {
		data.nettAmount = json['nett_amount'] is String
				? num.tryParse(json['nett_amount'])
				: json['nett_amount'];
	}
	if (json['reimbursement'] != null) {
		data.reimbursement = json['reimbursement'] is String
				? num.tryParse(json['reimbursement'])
				: json['reimbursement'];
	}
	if (json['error_message'] != null) {
		data.errorMessage = json['error_message'];
	}
	if (json['bank_account_name'] != null) {
		data.bankAccountName = json['bank_account_name'].toString();
	}
	if (json['bank_account_number'] != null) {
		data.bankAccountNumber = json['bank_account_number'].toString();
	}
	if (json['bank_name'] != null) {
		data.bankName = json['bank_name'].toString();
	}
	if (json['bank_code'] != null) {
		data.bankCode = json['bank_code'].toString();
	}
	if (json['bank_branch_code'] != null) {
		data.bankBranchCode = json['bank_branch_code'].toString();
	}
	if (json['status'] != null) {
		data.status = json['status'].toString();
	}
	if (json['created_by'] != null) {
		data.createdBy = json['created_by'];
	}
	if (json['created_at'] != null) {
		data.createdAt = json['created_at'].toString();
	}
	if (json['deleted_at'] != null) {
		data.deletedAt = json['deleted_at'].toString();
	}
	if (json['employee_name'] != null) {
		data.name = json['employee_name'].toString();
	}
	return data;
}

Map<String, dynamic> payslipsItemEntityToJson(PayslipsItemEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['data_type'] = entity.dataType;
	data['id'] = entity.id;
	data['company_id'] = entity.companyId;
	data['employee_id'] = entity.employeeId;
	data['payment_type_id'] = entity.paymentTypeId;
	data['payment_type_name'] = entity.paymentTypeName;
	data['paid_at'] = entity.paidAt;
	data['number'] = entity.number;
	data['start_date'] = entity.startDate;
	data['end_date'] = entity.endDate;
	data['total_days'] = entity.totalDays;
	data['actual_days'] = entity.actualDays;
	data['contribution'] = entity.contribution;
	data['contribution_amount'] = entity.contributionAmount;
	data['income_data'] =  entity.incomeData?.map((v) => v.toJson())?.toList();
	data['deduction_data'] =  entity.deductionData?.map((v) => v.toJson())?.toList();
	data['payments'] =  entity.payments?.map((v) => v.toJson())?.toList();
	data['total'] = entity.total;
	data['employee_cpf'] = entity.employeeCpf;
	data['employer_cpf'] = entity.employerCpf;
	data['nett_amount'] = entity.nettAmount;
	data['reimbursement'] = entity.reimbursement;
	data['error_message'] = entity.errorMessage;
	data['bank_account_name'] = entity.bankAccountName;
	data['bank_account_number'] = entity.bankAccountNumber;
	data['bank_name'] = entity.bankName;
	data['bank_code'] = entity.bankCode;
	data['bank_branch_code'] = entity.bankBranchCode;
	data['status'] = entity.status;
	data['created_by'] = entity.createdBy;
	data['created_at'] = entity.createdAt;
	data['deleted_at'] = entity.deletedAt;
	data['employee_name'] = entity.name;
	return data;
}